package com.example.mapper;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.controller.vo.EvaluationsVo;
import com.example.entity.Evaluations;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

/**
 * <p>
 * 评论表 Mapper 接口
 * </p>
 *
 * @author yzy
 * @since 2025-08-04
 */

public interface EvaluationsMapper extends BaseMapper<Evaluations> {

    Page<Evaluations> selectpage(Page<Evaluations> page, @Param("ew") QueryWrapper<Evaluations> queryWrapper);
    // 增加点赞数
    @Update("UPDATE Evaluations SET upvote_list = upvote_list + 1 WHERE id = #{id}")
    int incrementLikeCount(@Param("id") Integer id);

    // 减少点赞数
    @Update("UPDATE Evaluations SET upvote_list = upvote_list - 1 WHERE id = #{id} AND upvote_list > 0")
    int decrementLikeCount(@Param("id") Integer id);
    Evaluations selectByIdWithRelations(@Param("id") Integer id);

    // 关键：为Wrapper参数添加 @Param(Constants.WRAPPER) 注解
    IPage<EvaluationsVo> selectEvalVoPage(
            Page<EvaluationsVo> page,
            @Param(Constants.WRAPPER) Wrapper<EvaluationsVo> queryWrapper  // 修正此处注解
    );
}
